package top.lixunda.ecommerce.server.good.api.entity.vo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import top.lixunda.common.utils.ObjectValidators;
import top.lixunda.ecommerce.server.good.api.entity.db.PageInfoShowDO;

import java.util.List;

/**
 * 前端主页走马灯数据VO
 *
 * @author lixunda
 * @version time:2020/3/20 16:25
 */
@ApiModel("前端主页走马灯数据VO")
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
public class PageCarouselVO {

    @ApiModelProperty("数据id")
    private Integer id;

    @ApiModelProperty("数据类型")
    private String type;

    @ApiModelProperty("大标题")
    private String title;

    @ApiModelProperty("顺序号")
    private Integer sequence;

    @ApiModelProperty("图片")
    private String image;

    @ApiModelProperty("图片文件编号")
    private Integer imageFileId;

    @ApiModelProperty("背景图片")
    private String backImage;

    @ApiModelProperty("背景图片文件编号")
    private Integer backImageFileId;

    @ApiModelProperty("主商品编号")
    private Integer linkGoodId;

    @ApiModelProperty("主商品详细信息")
    private GoodConvertVO linkGood;

    @ApiModelProperty("次商品详细信息列表")
    private List<GoodConvertVO> goods;

    @ApiModelProperty("展示方式，LEFT RIGHT")
    private String direction;

    /**
     * 转换数据
     *
     * @param pageInfoShowDO 页面信息数据
     * @param goodConvertVO  主商品详细信息
     * @param list           此商品详细信息里列表
     * @return PageCarouselVO
     * @see top.lixunda.ecommerce.server.good.api.entity.dto.PageIndexCarouselInsertDTO
     */
    public static PageCarouselVO fromPageInfoShowDO(PageInfoShowDO pageInfoShowDO,
                                                    GoodConvertVO goodConvertVO, List<GoodConvertVO> list) {
        if (ObjectValidators.isEmpty(pageInfoShowDO)) {
            return null;
        }
        return new PageCarouselVO()
                .setId(pageInfoShowDO.getId())
                .setType(pageInfoShowDO.getType())
                .setGoods(list)
                .setLinkGood(goodConvertVO)
                .setLinkGoodId(Integer.valueOf(pageInfoShowDO.getLink()))
                .setTitle(pageInfoShowDO.getContent5())
                .setSequence(pageInfoShowDO.getSequence())
                .setImage(pageInfoShowDO.getImage1())
                .setImageFileId(pageInfoShowDO.getImageFile1())
                .setBackImage(pageInfoShowDO.getImage2())
                .setBackImageFileId(pageInfoShowDO.getImageFile2())
                .setDirection(pageInfoShowDO.getContent6());
    }

}
